<template>
  <div>
    <div @click="clickHandler" class="clickBtn">
      <el-input v-model="currentValue" readonly>
        <template slot="append">
          <a href="javascript:;" style="font-size: 20px">
            <i class="el-icon-more"></i>
          </a>
        </template>
      </el-input>
    </div>
    <el-dialog append-to-body
      ref="mydialog"
      :title="title"
      :visible.sync="show"
      :withHeader="false"
      class="m-dialog"
      :close-on-click-modal="false"
      @close="close"
    >
      <el-container>
        <el-main>
          <el-row>
            <el-col>
              <slot-tabale
                ref="slotTable"
                v-bind="$attrs"
                v-on="$listeners"
                @dbcell="dbCellHandler"
              ></slot-tabale>
            </el-col>
          </el-row>
        </el-main>
        <!-- <div slot="footer" class="dialog-footer">
          <el-button>取 消</el-button>
          <el-button type="primary" :loading="loading">
            {{ loading ? "提交中 ..." : "确 定" }}</el-button
          >
        </div> -->
      </el-container>
    </el-dialog>
  </div>
</template>

<script>
import SlotTabale from "./slotTabale.vue";
export default {
  name: "InputDialog",
  components: { SlotTabale },
  props: {
    value: {
      type: [String,Number],
      default: "",
    },
    text: {
      type: [String,Number],
      required: true,
    },
    isDisabled:{
      type:Boolean,
      default:false
    },
    infoTip:{
      type:Boolean,
      default:false
    },
    infoText:{
      type:String,
      default:''
    }
  },
  data() {
    return {
      show: false,
      loading: false,
    };
  },
  computed: {
    title() {
      return this.$attrs.config.title;
    },
    currentValue: {
      get: function () {
        return this.value;
      },
      set: function (newValue) {
        this.$emit("input", newValue);
      },
    },
  },
  methods: {
      close(){
          this.$refs.slotTable.$attrs.config.tableForm.data = {} ;
      },
    clickHandler() {
      if (this.isDisabled) return
      if(this.infoTip){
        this.$alert(this.infoText, "提示", {
          type: "warning",
          confirmButtonText: "关闭",
        });
        return
      }
      this.show = true;
      this.$nextTick(()=>{
        this.$refs.slotTable.findList();
      })
    },

    dbCellHandler(row) {
      this.show = false;
      this.$emit("input", row[this.text]);
      this.$emit("getrow", row);
    },
  },
};
</script>

<style lang="scss" scoped>
.clickBtn {
  ::v-deep .el-input-group--append .el-input__inner, .el-input-group__prepend {
    cursor: pointer;
  }
}
</style>
